package com.liugai.lgeachday.controller;

import com.liugai.lgeachday.entity.User;
import com.liugai.lgeachday.request.Response;
import com.liugai.lgeachday.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController()
@RequestMapping(value = "/user", produces = { "application/json;charset=UTF-8" })
public class UserController implements ControllerInterface<User> {

    @Autowired
    private UserService userService;



    @Override
    @RequestMapping(value = "getUserInfo",method = RequestMethod.GET)
    @ResponseBody
    public Response queryObject(int id) {
        return userService.queryObject(id);
    }

    @Override
    @RequestMapping("getUserList")
    @ResponseBody
    public Response queryObjectList() {
        System.out.println("查询所有用户");
        return userService.queryObjectList();
    }

    @Override
    public Response updateObject(User obj) {
        return userService.updateObject(obj);
    }

    @Override
    public Response insertObject(User obj) {
        return userService.insertObject(obj);
    }

    @Override
    public Response deleteObject(int id) {
        return userService.deleteObject(id);
    }

    @RequestMapping(value = "register", method = RequestMethod.GET)
    @ResponseBody
    public Response register(User user, HttpServletRequest request) {
        System.out.println(user);
        System.out.println(request);
        return userService.register(user);
    }

    @RequestMapping(value = "login", method = RequestMethod.GET)
    @ResponseBody
    public Response login(User user, HttpServletRequest request) {
        System.out.println(user);
        System.out.println(request);
        return userService.login(user);
    }

    @RequestMapping(value = "updateHead", method = RequestMethod.POST)
    public Response updateHead(@RequestParam(value = "file") MultipartFile file, Model model, HttpServletRequest request) {
        return userService.updateHead(file, request);
    }

}